//
//  PickView.m
//  XiangMu
//
//  Created by 康世标 on 15/8/11.
//  Copyright (c) 2015年 康世标. All rights reserved.
//

#import "PickView.h"

@implementation PickView

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/
-(id)initWithFrame:(CGRect)frame{
   
    if (self=[super initWithFrame:frame])
    {
      self.backgroundColor=CL_efeff4;
//        pickView=[[UIPickerView alloc]initWithFrame:CGRectMake(0, 0, 0, 0)];
//        pickView.backgroundColor = CL_efeff4;
//        
//        pickView.delegate = self;
//        pickView.showsSelectionIndicator = YES;
//        pickView.dataSource = self;
//        [self addSubview:pickView];
//        
//        _arr=[[NSMutableArray alloc]initWithObjects:@"00:00:00",@"01:00:00",@"02:00:00",@"03:00:00",@"04:00:00",@"05:00:00",@"06:00:00",@"07:00:00",@"08:00:00",@"09:00:00",@"10:00:00",@"11:00:00",@"12:00:00",@"13:00:00",@"14:00:00",@"15:00:00",@"16:00:00",@"17:00:00",@"18:00:00",@"19:00:00",@"20:00:00",@"21:00:00",@"22:00:00",@"23:00:00", nil];
//        _detas=[[NSMutableArray  alloc]initWithCapacity:0];
//        
//        _yesar = [[NSMutableArray alloc]initWithCapacity:0];
//        
//        _datasHui = [[NSMutableArray alloc] initWithCapacity:0];
//        
//         NSDate *date =[NSDate date];
//        for (int i=0; i<6; i++) {
//            NSDateFormatter*dateformatter=[[NSDateFormatter alloc]init];
//            [dateformatter setDateFormat:@"EEEE"];
//            
//           
//            NSDate *nextDat = [NSDate dateWithTimeInterval:i*86400 sinceDate:date];//后一天
//            
//            NSString *  locationString=[dateformatter stringFromDate:nextDat];
//        
//            
//            [dateformatter setDateFormat:@"MM-dd"];
//            
//            NSString * string=[dateformatter stringFromDate:nextDat];
//            
//            [dateformatter setDateFormat:@"YYYY"];
//            
//            NSString * yesar=[dateformatter stringFromDate:nextDat];
//
//       
//            
//            [_datasHui addObject:string];
//            [_yesar addObject:yesar];
//            if (i==0) {
//                
//                [_detas addObject:[NSString stringWithFormat:@"今天%@",string]];
//            }
//            else if (i==1){
//                [_detas addObject:[NSString stringWithFormat:@"明天%@",string]];
//              
//            }
//            else if (i==2){
//                [_detas addObject:[NSString stringWithFormat:@"后天%@",string]];
//
//               
//            }
//            else if (i==3){
//                 [_detas addObject:[NSString stringWithFormat:@"%@%@",locationString,string]];
//            }
//            else if (i==4){
//                [_detas addObject:[NSString stringWithFormat:@"%@%@",locationString,string]];
//            }
//        
//
//        }

        dataPicker = [[UIDatePicker alloc]initWithFrame:CGRectMake(0, 0, kScreenW, 200)];
        dataPicker.minimumDate = [NSDate date];
        dataPicker.backgroundColor = CL_efeff4;
         [self addSubview:dataPicker];
        UIButton *queDingBtn=[UIButton buttonWithType:UIButtonTypeCustom];
        queDingBtn.frame=CGRectMake(self.frame.size.width/2+40, dataPicker.frame.origin.y+dataPicker.frame.size.height,self.frame.size.width/2-50 ,30);
        [queDingBtn setTitle:@"确定" forState:UIControlStateNormal];
        queDingBtn.backgroundColor=CL_00cc85;
        queDingBtn.tag=1;
      
        [queDingBtn addTarget:self action:@selector(btnCloik:) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:queDingBtn];
        
        UIButton*quXiaoBtn=[UIButton buttonWithType:UIButtonTypeCustom];
        
        quXiaoBtn.frame=CGRectMake(10, dataPicker.frame.origin.y+dataPicker.frame.size.height,self.frame.size.width/2-50 , 30);
        quXiaoBtn.backgroundColor=CL_00cc85;
        [quXiaoBtn setTitle:@"取消" forState:UIControlStateNormal];
        quXiaoBtn.tag=2;
        queDingBtn.layer.masksToBounds=YES;
        [queDingBtn.layer setCornerRadius:15];
        quXiaoBtn.layer.masksToBounds=YES;
        [quXiaoBtn.layer setCornerRadius:15];
        [quXiaoBtn addTarget:self action:@selector(btnCloik:) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:quXiaoBtn];
        
    }
    
    return self;
}


-(void)btnCloik:(UIButton *)btn {

    if (btn.tag==1) {
        
        if ([_delegate respondsToSelector:@selector(pickView:btnClokc:ShiJian:Year:IsOK:)])
            
      {

          NSDateFormatter * dateFormatter =[[NSDateFormatter alloc]init];
          [dateFormatter setDateFormat:@"YYY-MM-dd hh:mm:ss"];
          
          NSString * dateString = [dateFormatter stringFromDate:dataPicker.date];
          
//          NSLog(@"--%@",dataPicker.date);
          
            [_delegate pickView:self btnClokc:dateString ShiJian:nil Year:nil IsOK:YES];
            
        }
    }
    else{
        if ([_delegate respondsToSelector:@selector(pickView:btnClokc:ShiJian:Year:IsOK:)])
        {

             [_delegate pickView:self btnClokc:@"" ShiJian:@"" Year:@"" IsOK:NO];
        }

    }

}

@end
